//
//  SecondViewController.swift
//  TableView
//
//  Created by Garvin on 2020/5/4.
//  Copyright © 2020 Garvin. All rights reserved.
//

import UIKit

// swift协议默认是必须实现的
@objc protocol SendResult {
    @objc optional var message: String { get set }
    func sendMessage(msg: String) -> Void
    @objc optional func send(msg: String) -> String
}

class SecondViewController: UIViewController {
    
    weak var delegate: SendResult?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        
        self.extendedLayoutIncludesOpaqueBars = true
        
        let clickButton = UIButton(type: UIButton.ButtonType.custom)
        clickButton.frame = CGRect(x: 100, y: 100, width: 100, height: 100)
        clickButton.backgroundColor = UIColor.red
        clickButton.setTitle("返回", for: UIControl.State.normal)
        clickButton.addTarget(self, action: #selector(backAction(_:)), for: UIControl.Event.touchUpInside)
        self.view.addSubview(clickButton)
    }
    
    @objc func backAction(_ button: UIButton) {
        self.navigationController?.popViewController(animated: true)
        
        if self.delegate != nil {
            delegate?.sendMessage(msg: "I back")
        }
    }

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}
